package com.chookss.home.audit.adapter;

import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.audit.shop.ShopDetailActivity;
import com.chookss.home.entity.ReimbursementDetailEntity;
import com.chookss.tools.ClearMoreZeroUtil;
import com.chookss.tools.GlideUtils;
import com.chookss.view.RoundCornerImageView;

import java.util.List;

public class ShopChoiceAdapter extends BaseQuickAdapter<ReimbursementDetailEntity.GoodsInfosBean, BaseViewHolderEx> {
    private Activity context;

    public ShopChoiceAdapter(int layoutResId, Activity context, @io.reactivex.annotations.Nullable List<ReimbursementDetailEntity.GoodsInfosBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, ReimbursementDetailEntity.GoodsInfosBean entity) {
        RelativeLayout rlType = helper.getView(R.id.rlType);
        TextView tvTitle = helper.getView(R.id.tvTitle);
        View line = helper.getView(R.id.line);
        TextView tvType = helper.getView(R.id.tvType);
        TextView tvInit = helper.getView(R.id.tvInit);
        RoundCornerImageView ivImg = helper.getView(R.id.ivImg);
        View emptyView = helper.getView(R.id.emptyView);
        if(helper.getItemPosition()==getData().size()-1){
            line.setVisibility(View.GONE);
        }else{
            line.setVisibility(View.VISIBLE);
        }
        emptyView.setVisibility(View.VISIBLE);
        tvInit.setText("所属人:" + entity.getOwnerEmployeeName() + "   所属项目组:" + entity.getGroupName());
        GlideUtils.load(context, entity.getImageUrl(), ivImg, R.drawable.default_news);
        tvType.setVisibility(View.GONE);
        String  title = entity.getGoodsName() + " <font color='#999999'>" + entity.getGoodsCode() + "</font> " + ClearMoreZeroUtil.subZeroAndDot(entity.getAmt()) + "元";
        tvTitle.setText(Html.fromHtml(title));
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Urls.antiShake.check()) {
                    return;
                }
                Intent intent = new Intent(context, ShopDetailActivity.class);
                intent.putExtra("goodsCode", entity.getGoodsCode());
                context.startActivity(intent);
            }
        });
    }
}
